<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>Crypt Class - Fuel Documentation</title>
	<link href="../assets/css/main.css" media="screen" rel="stylesheet" />
	<script type="text/javascript" src="../assets/js/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="../assets/js/nav.js"></script>
	<script type="text/javascript" src="../assets/js/highlight.pack.js"></script>
	<script type="text/javascript">
		$(function() {
			show_nav('classes', '../');
		});
		hljs.tabReplace = '    ';
		hljs.initHighlightingOnLoad();
	</script>
</head>
<body>

	<header>
		<h1>Fuel Documentation</h1>
	</header>

	<div id="main-nav"></div>

	<section id="content">
		<h2>Crypt Class</h2>

		<p>
			The Crypt class allows encrypt or decrypt a string. The Crypt class is also used internally by for example the Fuel Sessions class.
			It is <strong>very important</strong> that you configure a truly random salt for your application, even if you don't use the Crypt class directly.
		</p>

		<section>
			<h2>Configuration</h2>

			<p>
				The Crypt class is configured through the <kbd>app/config/crypt.php</kbd> configuration file. It is already populated with default configuration values.</p>
			<p>The following configuration settings can be defined:</p>
			<table class="config">
				<tbody>
					<tr class="header">
						<th>Param</th>
						<th>Type</th>
						<th>Default</th>
						<th>Description</th>
					</tr>
					<tr>
						<th>salt</th>
						<td>string</td>
						<td><pre class="php"><code>'sup3rs3Cr3tk3y564'</code></pre></td>
						<td>
							Random salt value used in the encryption routines for extra entropy. Make sure you set this to something unique and random!
						</td>
					</tr>
					<tr>
						<th>use_mcrypt</th>
						<td>boolean</td>
						<td><pre class="php"><code>true</code></pre></td>
						<td>
							Optional: Indicates if you want to use PHP's Mcrypt library if available. It is a lot faster, but might cause your data not to be portable anymore (all target platforms need to have Mcrypt installed as well).
						</td>
					</tr>
					<tr>
						<th>mcrypt_cipher</th>
						<td>integer</td>
						<td><pre class="php"><code>MCRYPT_RIJNDAEL_256</code></pre></td>
						<td>
							Optional: http://www.php.net/manual/en/mcrypt.ciphers.php for available ciphers.
						</td>
					</tr>
					<tr>
						<th>mcrypt_mode</th>
						<td>integer</td>
						<td><pre class="php"><code>MCRYPT_MODE_CBC</code></pre></td>
						<td>
							Optional: http://www.php.net/manual/en/mcrypt.constants.php for available cipher modes.
						</td>
					</tr>
				</tbody>
			</table>
		</section>

		<article>
			<h4>encode($value, $salt = false)</h4>
			<p>The <strong>encode</strong> method encrypts a string value, optionally with a custom salt.</p>
			<table class="method">
				<tbody>
				<tr>
					<th class="legend">Static</th>
					<td>No</td>
				</tr>
				<tr>
					<th>Parameters</th>
					<td>
						<table class="parameters">
							<tr>
								<th>Param</th>
								<th>Default</th>
								<th class="description">Description</th>
							</tr>
							<tr>
								<th><kbd>$value</kbd></th>
								<td><i>Required</i></td>
								<td>String value to encode.</td>
							</tr>
							<tr>
								<th><kbd>$salt</kbd></th>
								<td><pre class="php"><code>false</code></pre></td>
								<td>Optional custom salt value to be used to add more entropy to the value to encode.</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<th>Returns</th>
					<td>string</td>
				</tr>
				<tr>
					<th>Example</th>
					<td>
<pre class="php"><code>// encode a variable with a custom salt
$value = Crypt::encode($value, 'R@nd0mS@1t');</code></pre>
					</td>
				</tr>
				</tbody>
			</table>
		</article>

		<article>
			<h4>decode($value, $salt = false)</h4>
			<p>The <strong>decode</strong> method decrypts a string value, optionally with a custom salt.</p>
			<table class="method">
				<tbody>
				<tr>
					<th class="legend">Static</th>
					<td>No</td>
				</tr>
				<tr>
					<th>Parameters</th>
					<td>
						<table class="parameters">
							<tr>
								<th>Param</th>
								<th>Default</th>
								<th class="description">Description</th>
							</tr>
							<tr>
								<th><kbd>$value</kbd></th>
								<td><i>Required</i></td>
								<td>String value to decode.</td>
							</tr>
							<tr>
								<th><kbd>$salt</kbd></th>
								<td><pre class="php"><code>false</code></pre></td>
								<td>Optional custom salt value used when the <kbd>$value</kbd> was encoded.</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<th>Returns</th>
					<td>mixed - String value with the decoded value, or <kbd>false</kbd> if the value could not be decoded.</td>
				</tr>
				<tr>
					<th>Example</th>
					<td>
<pre class="php"><code>// decode a variable with a custom salt
$value = Crypt::decode($value, 'R@nd0mS@1t');</code></pre>
					</td>
				</tr>
				<tr>
					<th>Throws</th>
					<td><strong>Exception</strong> in case the <kbd>$value</kbd> passed was encoding using the Mcrypt library, but Mcrypt is not available to decode it.</td>
				</tr>
				</tbody>
			</table>
		</article>


	</section>

	<section id="footer">
		<p>
			<a href="http://fuelphp.com">Fuel</a> is released under the MIT license.<br />
			&copy; 2010 - 2011 Fuel Development Team
		</p>
	</section>

</body>
</html>
